﻿using System.Activities.Presentation.Model;
using System.Activities.Presentation.Services;
using System.Activities.Presentation.View;
using System.Collections;
using System.Collections.Generic;
using System.Windows;

namespace Headsight.BPMN2WF.WF.Impl
{
    public class ModelItemFlowSwitch : AbstractModelItem
    {
        public ModelItemFlowSwitch(ModelItem modelItem, ViewStateService viewStateService, ViewService viewService)
            : base(modelItem, viewStateService, viewService)
        {
        }

        public override double ActualWidth
        {
            get { return 60; }
        }

        public override double ActualHeight
        {
            get { return 75; }
        }

        public override IList<ModelItem> ImmediateChildren
        {
            get
            {
                var result = new List<ModelItem>();

                var casesProp = GetValue(InnerItem, "Cases") as IDictionary;
                if (casesProp != null)
                    foreach (var each in casesProp.Values)
                        result.Add((ModelItem)each);
                return result;
            }
        }

        public override Point AlignChildren()
        {
            // Alignment: Set Y parameter to minimun the Y of FlowSwitch

            foreach (var each in ImmediateChildren)
            {
                var child = ModelItemFactory.Create(each, InnerViewStateService, InnerViewService);
                
                if (child.ShapeLocation.Y < (ShapeLocation.Y + 50))
                    child.ShapeLocation = new Point(child.ShapeLocation.X, (ShapeLocation.Y + 50));
            }
            return new Point();
        }

        public override void ResetConnector()
        {
        }
    }
}
